export class ResponseUtils<T> {
  code: number;
  message: string;
  data?: T;
  timestamp: number;

  constructor(code: number, message: string, data?: T) {
    this.code = code;
    this.message = message;
    this.data = data;
    this.timestamp = Date.now();
  }

  static success<T>(data?: T, message: string = '请求成功'): ResponseUtils<T> {
    return new ResponseUtils(200, message, data);
  }

  static warning<T>(message: string = '警告信息'): ResponseUtils<T> {
    return new ResponseUtils(409, message);
  }

  static error<T>(message: string = '失败信息'): ResponseUtils<T> {
    return new ResponseUtils(400, message);
  }

  static notFound<T>(message: string = '资源未找到'): ResponseUtils<T> {
    return new ResponseUtils(404, message);
  }

  static unauthorized<T>(message: string = '未授权访问'): ResponseUtils<T> {
    return new ResponseUtils(401, message);
  }

  static forbidden<T>(message: string = '禁止访问'): ResponseUtils<T> {
    return new ResponseUtils(403, message);
  }

  static custom<T>(code: number, message: string, data?: T): ResponseUtils<T> {
    return new ResponseUtils(code, message, data);
  }
}
